package br.com.clinica.supercao.dao.impl;

import java.util.ArrayList;
import java.util.List;

import br.com.clinica.supercao.JPA.GenericDAOSuperCao;
import br.com.clinica.supercao.dao.FuncionarioDAO;
import br.com.clinica.supercao.entity.Funcionario;
import br.com.clinica.supercao.entity.filter.FuncionarioSearchFilter;
import br.com.rpteixeira.persistence.DAO;

public class FuncionarioDAOImpl extends AbstractPessoaDAO<Funcionario, FuncionarioSearchFilter>implements FuncionarioDAO{
	
	@Override
	protected void doPrepareQuery(StringBuffer query,
			FuncionarioSearchFilter entitySearchFilter) {
		
	}
	@Override
	protected Object[] doPrepareQueryFrom(StringBuffer query,
			FuncionarioSearchFilter entitysearchfilter) {
		Object[] arg = super.doPrepareQueryFrom(query, entitysearchfilter);
		List<Object> args = new ArrayList<Object>();
		for (Object object : arg) {
			args.add(object);
		}
		if(entitysearchfilter.getLogin()!=null && !entitysearchfilter.getLogin().isEmpty()){
			query.append(" and oEntidade.login=?");
			args.add(entitysearchfilter.getLogin());
		}
		if(entitysearchfilter.getSenha()!=null && !entitysearchfilter.getSenha().isEmpty()){
			query.append(" and oEntidade.senha=?");
			args.add(entitysearchfilter.getSenha());
		}
	return args.toArray();
	}
	public DAO<Funcionario> getDao(){
		return new GenericDAOSuperCao<Funcionario>();
	} 
}
